package com.x.erp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.CooperationDao;
import com.x.erp.model.Cooperation;
import com.x.erp.rpc.CooperationRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 启辕合作记录服务
 */
@Component
@Service(interfaceName = "com.x.erp.rpc.CooperationRpcService", timeout = 60000)
public class CooperationService extends BaseService implements CooperationRpcService {

	@Autowired
	private CooperationDao cooperationDao;// 启辕合作DAO

	/**
	 * 查询启辕合作记录
	 * @param cooperation
	 * @return
	 */
	@Override
	public List<Cooperation> selectCooperationList(Cooperation cooperation) {
		try {
			return cooperationDao.selectCooperationList(cooperation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 新增启辕合作记录
	 * @param cooperation
	 * @return
	 */
	@Override
	public Cooperation insertCooperation(Cooperation cooperation) {
		cooperation.setCooperationCreateTime(this.getDate(0));
		try {
			return this.insert(cooperation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 修改启辕合作记录
	 * @param cooperation
	 * @return
	 */
	@Override
	public Integer updateCooperation(Cooperation cooperation) {
		try {
			return this.update(cooperation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 查询启辕合作记录数量
	 * @param cooperation
	 * @return
	 */
	public Integer selectCooperationNum(Cooperation cooperation) {
		try {
			return cooperationDao.selectCooperationNum(cooperation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}
}
